package com.example.kt_temp.ui.viewmodel

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Description
import androidx.compose.material.icons.filled.SmartDisplay
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.example.kt_temp.model.entity.Category
import com.example.kt_temp.model.entity.DataType
import com.example.kt_temp.model.entity.SwiperEntity
import com.example.kt_temp.model.service.HomeService

class MainViewModel:ViewModel() {

    private val homeService = HomeService.instance()

    //分类数据是否加载成功
    var categoryLoaded by mutableStateOf(false)
        private set

    //分类数据
    var categories by mutableStateOf(
        listOf(
            Category("思想政治1","1"),
            Category("法律法规2","2"),
            Category("职业道德3","3"),
            Category("诚信自律4","4")
        )
    )
        private set  //数据只允许在内部设置

    suspend fun categoryData(){
       val categoryRes = homeService.category()
        if(categoryRes.code == 0){
            categories = categoryRes.data
            categoryLoaded = true
        }else{
            //失败 ，读取message
            val message =categoryRes.message
        }
    }

    //当前分类下标
    var categoryIndex by mutableStateOf(0)
        private  set

    //跟新下标
    fun updateCategoryIndex(index:Int){
        categoryIndex = index
    }

    //类型数据
    val types by mutableStateOf(
        listOf(
            DataType("相关资讯", Icons.Default.Description),
            DataType("视频课程", Icons.Default.SmartDisplay),
        )
    )

    //当前类型下标
    var currentTypeIndex by mutableStateOf(0)
        private  set

    //是否文章列表
    var showArticleList by mutableStateOf (true)
    private set

    //跟新下标
    fun updateTypesIndex(index:Int){
        currentTypeIndex = index
        showArticleList = currentTypeIndex==0
    }

    //轮播图数据
    var swiperData by mutableStateOf(
        listOf(
            SwiperEntity("https://docs.bughub.icu/compose/assets/banner1.webp"),
            SwiperEntity("https://docs.bughub.icu/compose/assets/banner2.webp"),
            SwiperEntity("https://docs.bughub.icu/compose/assets/banner3.webp"),
            SwiperEntity("https://docs.bughub.icu/compose/assets/banner4.jpg"),
            SwiperEntity("https://docs.bughub.icu/compose/assets/banner5.jpg"),
        )
    )
        private set

    var swiperLoaded by mutableStateOf(false)
        private set

    suspend fun swiperData(){
        val swiperRes=homeService.banner()
        if(swiperRes.code ==0 && swiperRes.data!=null){
            swiperData = swiperRes.data
            swiperLoaded = true
        }else{
            val message =swiperRes.message
        }
    }

    val notifications =
        listOf("屎大颗大萨达默哀","大健康拉萨的骚得离谱大","大叔大婶了，发V领第三代客服吗，按什么大道看到")

}